<?php
	require_once dirname(BASEPATH) . '/application/controllers/system/_init.php';
	
	abstract class abs_cafe extends _init
	{	
		function index(){
			$this->set_header_main();
			$this->set_navigation(array('<i class="icon-home"></i>หน้าแรก' => base_url(),
										'รายชื่อร้านกาแฟ' => base_url() . 'cafe'));
				
			$start_index = $this->input->get('p');
			$alphabet = $this->input->get('c');
			$language = $this->input->get('u');
				
			if (empty($start_index))
				$page_index = 0;
				
			$display_length = 8;
			
			$this->load->library('define/general_define');
			$this->load->library('alphabet');
				
			$this->load->model('local/data/cafe/mod_cafe');
			$result = $this->mod_cafe->search_cafe($alphabet, 1, null, null, ($start_index-1) * $display_length, $display_length);
				
			$data_content_0['cafe_list'] = $result['result'];
			$data_content_0['page_count'] = ceil($result['row_count'] / $display_length);
				
			$data_content_0['page_start_index'] = $start_index;
			$data_content_0['current_alphabet'] = $alphabet;
				
			switch ($language){
				case 'e': case 'E':
					$data_content_0['alphabet'] = $this->alphabet->get_english_alphabet();
					$data_content_0['current_language'] = 'e';
					break;
				case 't': case 'T':
					$data_content_0['alphabet'] = $this->alphabet->get_thai_alphabet();
					$data_content_0['current_language'] = 't';
					break;
				case 'n': case 'N':
					$data_content_0['alphabet'] = $this->alphabet->get_numeric();
					$data_content_0['current_language'] = 'n';
					break;
				default:
					$data_content_0['alphabet'] = $this->alphabet->get_english_alphabet();
					$data_content_0['current_language'] = null;
					break;
			}
			
			$this->template->write('content_1', $this->load->view('cafe/list/frm_list', $data_content_0, true));
			$this->template->render();
		}
		function ranking(){
			$this->set_header_main();
			
			// banner list
			$this->load->model('local/data/mod_banner_cafe');
			$data_1['banner_list'] = $this->mod_banner_cafe->get_banner_list(2);
			
			$this->load->model('local/data/rate/mod_rate_result');
			$data_2['ranking_list'] = $this->mod_rate_result->get_top_cafe();
						
			$this->template->write('content_1', $this->load->view('cafe/ranking/frm_cafe_ranking', $data_2, true));
			$this->template->write('right_sidebar', $this->load->view('home/frm_right_sidebar', $data_1, true));						
			$this->template->render();
		}
	}
?>